<?php

class Model_Application extends PhalApi_Model_NotORM {


    public function getById($id) {
        return $this->getORM()
            ->select('*')
            ->where('id = ?', $id)
            ->fetch();
    }

    public function getlist($where=[]) {

        return $this->getORM()
            ->where($where)
            ->select('id as Id,appid,secretkey')
            ->fetchAll();

    }

    public function add($data = []) {
        if (count($data) == 0) return false;
        return $this->getORM()
            ->insert($data);
    }

    public function update($data = [], $id = null) {

        if (count($data) == 0) return false;
        if (!$id) return false;

        return $this->getORM()
            ->where('id', $id)
            ->update($data);
    }

    public function deleteById($id) {
        if (!$id) return false;
        return $this->getORM()
            ->where('id', $id)
            ->delete();

    }

    protected function getTableName($id) {
        return 'applications';
    }
}
